using Share;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using UnityEngine;
using UnityEngine.Tilemaps;

namespace Tower
{
    public class BattleField : SingletonMono<BattleField>
    {
        [SerializeField]
        public int MapSizeX = 10;
        [SerializeField]
        public int MapSizeY = 10;

        [SerializeField]
        TileBase m_Ground;

        [SerializeField]
        Tilemap m_TileMap;

        public void DoStart()
        {
            // 检查必要的组件是否已设置
            if (m_TileMap == null)
            {
                Debug.LogError("Tilemap is not assigned!");
                return;
            }

            if (m_Ground == null)
            {
                Debug.LogError("Ground tile is not assigned!");
                return;
            }

            // 清除现有的tile
            m_TileMap.ClearAllTiles();

            // 使用m_Ground铺满整个MapSize的地图
            for (int x = 0; x < MapSizeX; x++)
            {
                for (int y = 0; y < MapSizeY; y++)
                {
                    Vector3Int tilePosition = new Vector3Int(x, y, 0);
                    m_TileMap.SetTile(tilePosition, m_Ground);
                }
            }

            Debug.Log($"Map generated with size: {MapSizeX}x{MapSizeY}");
        }

        public void DoClose()
        {

        }
    }
}
